﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MachineBuildingSystem
{
    public partial class IntegrationCfgForm : XtraForm
    {
        public IntegrationCfgForm()
        {
            InitializeComponent();
        }

        private void IntegrationCfgForm_Load(object sender, EventArgs e)
        {
            int way = int.Parse(ConfigurationManager.AppSettings["ExcuteFormulaWay"].ToString());
            rgpExcuteFormulaWay.SelectedIndex = way;

            int deliveryWay = int.Parse(ConfigurationManager.AppSettings["DeliveryWay"].ToString());
            rgpDeliveryWay.SelectedIndex = deliveryWay;

        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                cfa.AppSettings.Settings["ExcuteFormulaWay"].Value = rgpExcuteFormulaWay.SelectedIndex.ToString();
                cfa.AppSettings.Settings["DeliveryWay"].Value = rgpDeliveryWay.SelectedIndex.ToString();
                cfa.Save();
                ConfigurationManager.RefreshSection("appSettings");           
            }
            catch (Exception ex)
            {
                MessageBox.Show("修改失败：" + ex.Message);
                return;
            }
            MessageBox.Show("修改成功！");
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
